<template>
  <div class="aui-card-list">
  <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="表分类">
          <el-select v-model="dataForm.ruleClass" placeholder="表分类" clearable>
                <el-option v-for="template in $getDictList('DPD_RULE_CLASS', true)" :key="template.val"
                  :label="template.label" :value="template.val"></el-option>
              </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="数据库类型">
        <el-select v-model="dataForm.dbType" placeholder="数据库类型" clearable>
                <el-option v-for="template in $getDictList('DATABASE_TYPE', true)" :key="template.val"
                  :label="template.label" :value="template.val"></el-option>
              </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="规则名称">
          <el-input v-model="dataForm.ruleName" placeholder="规则名称" clearable></el-input>
        </el-form-item>
      </el-col>
  </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body ">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('dpd:dpdRule:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add')
            }}</el-button>
          <el-button v-if="$hasPermission('dpd:dpdRule:delete')" type="danger" @click="deleteHandle()">{{
            $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize
        @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex"
        :data="dataList" max-height="auto">
        <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
        <vxe-table-column field="ruleCode" title="规则编号">
        </vxe-table-column>
        <vxe-table-column field="ruleName" title="规则名称">
        </vxe-table-column>
        <vxe-table-column field="ruleClass" title="表分类">
          <template slot-scope="scope">
            {{$getDictLabel('DPD_RULE_CLASS', scope.row.ruleClass)}}
          </template>
        </vxe-table-column>
        <vxe-table-column field="dbType" title="数据库类型">
          <template slot-scope="scope">
            {{$getDictLabel('DATABASE_TYPE', scope.row.dbType)}}
          </template>
        </vxe-table-column>
        <vxe-table-column field="remark" title="备注说明">
        </vxe-table-column>
        <vxe-table-column field="updater" title="更新者">
        </vxe-table-column>
        <vxe-table-column field="updateDate" title="更新时间" align="center" width="140">
        </vxe-table-column>
        <vxe-table-column title="handle" width="150" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('dpd:dpdRule:update')" type="text" size="small" icon="el-icon-edit"
              @click="addOrUpdateHandle(scope.row)">{{
              $t('update') }}</el-button>
            <el-button v-if="$hasPermission('dpd:dpdRule:delete')" type="text" size="small" icon="el-icon-delete"
              @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      </div>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/dpd/dpdRule/page',
        getDataListIsPage: true,
        deleteURL: '/dpd/dpdRule',
        deleteIsBatch: true
      },
      dataForm: {
        ruleCode: '',
        ruleName: '',
        ruleClass: '',
        dbType: ''
      }
    }
  },
  components: {},
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let title = '新增'
      let id
      if (row) {
        title = '编辑'
        id = row.id
      }
      // 打开路由
      var router = {
        name: 'dpd-dpdRule-editForm',
        id: id,
        menuId: this.$route.meta.menuId,
        oldName: 'dpd-dpdRule',
        path: 'dpd/dpdRule-editForm',
        title: title + '-' + (row ? row.ruleName : '规则表')
      }
      var params = {
        timestamp: this.$xeutils.timestamp(),
        id: id
      }
      this.$options.methods.openNewTab(this.$router, router, params)
    }
  }
}
</script>
